package us.gaaoc.framework.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;

import us.gaaoc.framework.model.Attorney;
import us.gaaoc.framework.model.LegalPreparer;
import us.gaaoc.framework.model.Organizations;
import us.gaaoc.framework.model.Person;

public class LegalPreparerDAOHibernate extends GenericHibernateDAO<LegalPreparer, String, LegalPreparerDAO> implements
LegalPreparerDAO {

	private Logger LOG = Logger.getLogger(LegalPreparerDAOHibernate.class);

	protected LegalPreparerDAOHibernate() {

	}

	public Attorney findAttorneyByLegalPreparerUuid(String personUuid) {
		LOG.info("Inside the findAttorneyByLegalPreparerUuid ...");
		Query q = this.getSession().createQuery("select lp.attorney from LegalPreparer lp where lp = ?");


		q.setString(0, personUuid);	
		LOG.info("return of query  ...");
		return (Attorney)q.uniqueResult();

	}

	/**
	 * This method is deprecated because multiple agents can file with the same attorney
	 * Method is replaced by findLegalPreparerByPersonAndOrg and findAttorneyByLegalPreparerUuid.
	 */
	@Deprecated
	public Person findPersonByAttorneyUuid(String attorneyUuid) {
		new Exception("findPersonByAttorneyUuid - This is a deprecated method!").printStackTrace();
		Query q = this.getSession().createQuery("from LegalPreparer lp where lp.attorneyUuid = ?");
		q.setString(0, attorneyUuid);	
		return (Person)q.uniqueResult();
	}



	@Override
	public List<LegalPreparer> getLegalPreparers(Person personFiler,
			Organizations organization) {
		Query q = this.getSession().createQuery("from LegalPreparer lp where lp.person = ? and lp.organization = ?");
		q.setEntity(0,personFiler);
		q.setEntity(1, organization);
		return q.list();
	}

	/*
	public  LegalPreparer findLegalPreparerByPersonAndOrg(
			Person person, String org)
	{
		Query q = this.getSession().createQuery("from LegalPreparer lp where lp.person = ? and lp.organization = ?");
		q.setString(0,person.getUuid());
		q.setString(1, org);
		return (LegalPreparer)q.uniqueResult();	
	}
	*/
}


